<?php
    session_start();
    include_once(dirname(__FILE__). "/../../core/presenters/administration/taxonAdministration/class.taxonAdministration_Presenter.php");

    $pres = unserialize($_SESSION["tax_adm_pres"]);

    //--Récupération de informations
    if($_POST['nav'] == 'superFamille'){
        
        $order_id = $_POST['order'];
        $res = $pres->getSuperFamilleByOrder($order_id);
        
        $_SESSION["tax_adm_pres"] = serialize($pres);
        echo json_encode(constructRetour($res));
    }
    if($_POST['nav'] == 'famille'){
        $supFam_id = $_POST['supFam'];
        $res = $pres->getFamilleList($supFam_id);
        
        $_SESSION["tax_adm_pres"] = serialize($pres);
        echo json_encode(constructRetour($res));
    }
    if($_POST['nav'] == 'sousFamille'){
        $supFam_id = $_POST['supFam'];
        $fam_id = $_POST['fam'];
        $res = $pres->getSousFamilleList($fam_id, $supFam_id);
        
        $_SESSION["tax_adm_pres"] = serialize($pres);
        echo json_encode(constructRetour($res));
    }
    if($_POST['nav'] == 'tribu'){
        $supFam_id = $_POST['supFam'];
        $fam_id = $_POST['fam'];
        $sousFam_id = $_POST['sousFam'];
        $res = $pres->getTribuList($sousFam_id,$fam_id, $supFam_id);
        
        $_SESSION["tax_adm_pres"] = serialize($pres);
        echo json_encode(constructRetour($res));
    }
    if($_POST['nav'] == 'genre'){
        $supFam_id = $_POST['supFam'];
        $fam_id = $_POST['fam'];
        $sousFam_id = $_POST['sousFam'];
        $tribu_id = $_POST['tribu'];
        $res = $pres->getGenreList($sousFam_id,$fam_id, $supFam_id,$tribu_id);
        
        $_SESSION["tax_adm_pres"] = serialize($pres);
        echo json_encode(constructRetour($res));
    }
    if($_POST['nav'] == 'sousGenre'){
        $supFam_id = $_POST['supFam'];
        $fam_id = $_POST['fam'];
        $sousFam_id = $_POST['sousFam'];
        $tribu_id = $_POST['tribu'];
        $genre_id = $_POST['genre'];
        $res = $pres->getSousGenreList($sousFam_id,$fam_id, $supFam_id,$tribu_id,$genre_id);
        
        $_SESSION["tax_adm_pres"] = serialize($pres);
        echo json_encode(constructRetour($res));
    }
    
    //--Met en forme pour le retour vers js
    function constructRetour($res){
        $retour = array(array());
        for($i = 0; $i < count($res); $i++){
            $retour[$i]['id'] = $res[$i]->getId();
            $retour[$i]['nom'] = $res[$i]->getNom();
        }
        return $retour;
    }
?>